package com.example.javamaday.offer;

import com.example.javamaday.leetcode.base.ListNode;

public class GetOffer22 {

    public static void main(String[] args) {

    }

    private int k;
    private int index = 0;
    private ListNode listNode;

    public ListNode getKthFromEnd(ListNode head, int k) {
        this.k = k;
        scanListNode(head);
        return listNode;
    }

    public void scanListNode(ListNode head) {
        if (listNode != null) {
            return;
        }
        if (head == null) {
            return;
        }
        scanListNode(head.next);
        System.out.println(head.val);
        index++;
        if (index == k) {
            listNode = head;
        }
    }
}
